import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable, Subject} from 'rxjs';

/**
 * 父子组件同步消息对象
 */
export interface WebsiteVariable {
  weixinCodeCovers?: any;
}

@Injectable({
  providedIn: 'root'
})
export class WebsiteService {

  /**
   * Subject（特殊的Observable可观察对象，可以向多个Observer观察者多路推送消息）
   */
  private websiteSubject = new Subject<WebsiteVariable>();

  /**
   * 发布订阅消息
   */
  public websiteObservable = this.websiteSubject.asObservable();

  /**
   * 推送消息
   */
  public pushWebsiteVariable(websiteVariable: WebsiteVariable) {
    this.websiteSubject.next(websiteVariable);
  }

  constructor(private http: HttpClient) { }

  // 查询封面类别信息，包含封面信息
  selectCoverTypeJoinCover(coverType): Observable<any> {
    return this.http.post<any>(`/gdd/website/selectCoverTypeJoinCover`, coverType);
  }

  // 查询商品类别信息，包含商品信息
  selectGoodsTypeJoinGoods(goodsType): Observable<any> {
    return this.http.post<any>(`/gdd/website/selectGoodsTypeJoinGoods`, goodsType);
  }

  // 查询商品信息
  selectGoods(goods): Observable<any> {
    return this.http.post<any>(`/gdd/website/selectGoods`, goods);
  }
}
